package com.hsq.end_of_period;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestButton extends JFrame implements ActionListener {
    JButton btn1, btn2;
    JTextField textField;
    public TestButton() {
        this.setBounds(100, 100, 600, 400);
        this.setTitle("TestButton");
        this.setLayout(new FlowLayout());
        textField = new JTextField(20);
        btn1 = new JButton("Button1");
        btn2 = new JButton("Button2");
        btn1.addActionListener(this);
        btn2.addActionListener(this);
        this.add(btn1);
        this.add(btn2);
        this.add(textField);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new TestButton();
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btn1) textField.setText("Button1");
        if (e.getSource() == btn2) textField.setText("Button2");
    }
}
